const Koa = require('koa')
const app = new Koa()
const bodyparser = require('koa-bodyparser')
const errorHandler = require("./config/error-handle");
const cors = require("koa2-cors")
app.use(cors())
const users = require('./routes/users')
const auth = require('./routes/auth')
const file = require('./routes/file')
const book = require('./routes/book')
const comment = require("./routes/comment")
const role=require("./routes/role")
// error handler

// middlewares
app.use(bodyparser({
  enableTypes:['json', 'form', 'text']
}))
app.use(require('koa-static')(__dirname + '/public'))


// routes
app.use(users.routes(), users.allowedMethods())
app.use(auth.routes(), auth.allowedMethods())
app.use(file.routes(), file.allowedMethods())
app.use(book.routes(), book.allowedMethods())
app.use(comment.routes(), comment.allowedMethods())
app.use(role.routes(),role.allowedMethods())
// error-handling
app.on('error', errorHandler);

module.exports = app
